/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Administrar.java
 *
 * Created on 22/03/2011, 17:10:47
 */
package vistas;

import Renderers.LabelRenderer;
import comu.Configuracio;
import comu.Utilitats;
import controlador.CampControlador;
import controlador.ProducteControlador;
import controlador.ProductorControlador;
import controlador.autogenerats.exceptions.IllegalOrphanException;
import controlador.autogenerats.exceptions.NonexistentEntityException;
import entity.Camp;
import entity.Producte;
import entity.Productor;
import java.io.IOException;
import java.util.List;
import java.util.Observable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import controlador.AbonoControlador;
import controlador.FitosanitariControlador;
import controlador.UnitatsMesuraControlador;
import entity.Abono;
import entity.Fitosanitari;
import entity.UnitatsMesura;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Observer;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import vistas.textImg.Textos;

/**
 *
 * @author David
 */
public class Administrar extends javax.swing.JFrame implements Observer {

    Menu menu;
    JFileChooser fc = new JFileChooser();
    ProducteControlador productes;
    CampControlador camps;
    ProductorControlador productors;
    AbonoControlador abonos;
    FitosanitariControlador fitosanitaris;
    UnitatsMesuraControlador unitats;
    Camp camp;
    byte[] imgCamp;
    byte[] imgProducte;
    byte[] imgAbono;
    byte[] imgFitos;
    Producte producte;
    Productor productor;
    Fitosanitari fitosanitari;
    Abono abono;

    /** Creates new form Administrar */
    public Administrar(Menu menu) {
        this.menu = menu;
        productes = new ProducteControlador();
        camps = new CampControlador();
        productors = new ProductorControlador();
        abonos = new AbonoControlador();
        fitosanitaris = new FitosanitariControlador();
        unitats = new UnitatsMesuraControlador();

        initComponents();
        Utilitats.centrarVentana(this);
        try {
            updateProductes();
            updateCamps();
//            updateProductors();
        } catch (Exception ex) {
            ex.printStackTrace();
        }


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane6 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        btMenu1 = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        PanelCamps = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        llistaCamps = new javax.swing.JList();
        jPanel6 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        btModificarCamp = new javax.swing.JButton();
        btEliminarCamp = new javax.swing.JButton();
        lblNomCamp = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lblImgCamp = new javax.swing.JLabel();
        lblLocalitatCamp = new javax.swing.JLabel();
        lblProductorCamp = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jPanel7 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        btCrearCamp = new javax.swing.JButton();
        btBorrarDadesCamp = new javax.swing.JButton();
        lblImgCamp1 = new javax.swing.JLabel();
        tfNomCamp = new javax.swing.JTextField();
        tfLocalitatCamp = new javax.swing.JTextField();
        cbProuctorCamp = new javax.swing.JComboBox();
        PanelProductes = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        llistaProductes = new javax.swing.JList();
        jPanel8 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        btModificarProducte = new javax.swing.JButton();
        btEliminarProducte = new javax.swing.JButton();
        lblImgProducte = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lblNomProducte = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jPanel9 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        btCrearProducte = new javax.swing.JButton();
        btBorrarDadesProducte = new javax.swing.JButton();
        lblImgProducte1 = new javax.swing.JLabel();
        tfNomProducte = new javax.swing.JTextField();
        PanelProductor = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        llistaProductors = new javax.swing.JList();
        jPanel10 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        btModificarProductor = new javax.swing.JButton();
        btEliminarProductor = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        lblNomProductor = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jPanel11 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        btCrearProductor = new javax.swing.JButton();
        btBorrarDadesProductor = new javax.swing.JButton();
        tfNomProductor = new javax.swing.JTextField();
        PanelAbonos = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        llistaAbonos = new javax.swing.JList();
        jPanel12 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        btModificarAbono = new javax.swing.JButton();
        btEliminarAbono = new javax.swing.JButton();
        lblNomAbono = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        lblImgAbono = new javax.swing.JLabel();
        lblComposicioAbono = new javax.swing.JLabel();
        lblQuantitatAbono = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jPanel13 = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        btCrearAbono = new javax.swing.JButton();
        btBorrarDadesAbono = new javax.swing.JButton();
        lblImgAbono1 = new javax.swing.JLabel();
        tfNomAbono = new javax.swing.JTextField();
        tfComposicioAbono = new javax.swing.JTextField();
        cbBultoAbono = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        tfQuantitatAbono = new javax.swing.JTextField();
        cbUnitatAbono = new javax.swing.JComboBox();
        PanelFitosanitaris = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        llistaFitos = new javax.swing.JList();
        jPanel14 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        jLabel24 = new javax.swing.JLabel();
        btModificarFitos = new javax.swing.JButton();
        btEliminarFitos = new javax.swing.JButton();
        lblNomFitos = new javax.swing.JLabel();
        lblImgFitos = new javax.swing.JLabel();
        lblMateriaActivaFitos = new javax.swing.JLabel();
        lblComposicioFitos = new javax.swing.JLabel();
        jLabel25 = new javax.swing.JLabel();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        taProdAutoritzats = new javax.swing.JTextArea();
        lblDosisFitos = new javax.swing.JLabel();
        lblPlazSegFitos = new javax.swing.JLabel();
        lblNumRegFitos = new javax.swing.JLabel();
        lblDatFiFitos = new javax.swing.JLabel();
        jPanel15 = new javax.swing.JPanel();
        jLabel26 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel37 = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        taProdAutoFito1 = new javax.swing.JTextArea();
        btCrearFitos = new javax.swing.JButton();
        btBorrarDadesFitos = new javax.swing.JButton();
        lblImgFitos1 = new javax.swing.JLabel();
        tfNomFitos = new javax.swing.JTextField();
        tfMateriaActFitos = new javax.swing.JTextField();
        tfComposicioFitos = new javax.swing.JTextField();
        tfPlazSegFitos = new javax.swing.JTextField();
        tfNumRegFitos = new javax.swing.JTextField();
        cbUnitatDosisFitos = new javax.swing.JComboBox();
        jLabel38 = new javax.swing.JLabel();
        cbUnitaDisolucioFitos = new javax.swing.JComboBox();
        dcDataFiFito = new com.toedter.calendar.JDateChooser();
        ftfDosisFitos = new javax.swing.JFormattedTextField();
        jSeparator5 = new javax.swing.JSeparator();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane6.setViewportView(jTextArea1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btMenu1.setText(Textos.COMU_BOTO_MENU);
        btMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMenu1ActionPerformed(evt);
            }
        });

        jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jTabbedPane1StateChanged(evt);
            }
        });

        llistaCamps.setCellRenderer(new LabelRenderer());
        llistaCamps.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                llistaCampsValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(llistaCamps);

        jLabel1.setText(Textos.ADMIN_CAMP_NOM_CAMP);

        jLabel2.setText(Textos.ADMIN_CAMP_NOM_LOCALITAT);

        jLabel3.setText(Textos.ADMIN_CAMP_NOM_PRODUCTOR);

        btModificarCamp.setText(Textos.ADMIN_BOTO_MODIFICAR);
        btModificarCamp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btModificarCampActionPerformed(evt);
            }
        });

        btEliminarCamp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/eliminar_32x32.png"))); // NOI18N
        btEliminarCamp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEliminarCampActionPerformed(evt);
            }
        });

        lblNomCamp.setText("   ");

        jLabel4.setText(Textos.ADMIN_LABEL_DESCRIPCIO);

        lblLocalitatCamp.setText("   ");

        lblProductorCamp.setText("   ");

        org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(btModificarCamp)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btEliminarCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel6Layout.createSequentialGroup()
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblProductorCamp))
                    .add(jPanel6Layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblLocalitatCamp))
                    .add(jPanel6Layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblNomCamp))
                    .add(jLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 107, Short.MAX_VALUE)
                .add(lblImgCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel6Layout.createSequentialGroup()
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(lblNomCamp))
                        .add(17, 17, 17)
                        .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel2)
                            .add(lblLocalitatCamp))
                        .add(18, 18, 18)
                        .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel3)
                            .add(lblProductorCamp))
                        .add(31, 31, 31)
                        .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(btModificarCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btEliminarCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(lblImgCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel5.setText(Textos.ADMIN_CAMP_NOM_CAMP);

        jLabel6.setText(Textos.ADMIN_CAMP_NOM_LOCALITAT);

        jLabel7.setText(Textos.ADMIN_CAMP_NOM_PRODUCTOR);

        btCrearCamp.setText(Textos.ADMIN_CAMP_BOTO_CREAR);
        btCrearCamp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCrearCampActionPerformed(evt);
            }
        });

        btBorrarDadesCamp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/borrar.gif"))); // NOI18N
        btBorrarDadesCamp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBorrarDadesCampActionPerformed(evt);
            }
        });

        lblImgCamp1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png"))); // NOI18N
        lblImgCamp1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblImgCamp1MouseClicked(evt);
            }
        });

        cbProuctorCamp.setModel(Utilitats.getComboBoxModel(productors.findProductorEntities()));
        cbProuctorCamp.setRenderer(new LabelRenderer());

        org.jdesktop.layout.GroupLayout jPanel7Layout = new org.jdesktop.layout.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .add(btCrearCamp)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(btBorrarDadesCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(268, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel7Layout.createSequentialGroup()
                .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel7Layout.createSequentialGroup()
                        .add(jLabel5)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfNomCamp, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel7Layout.createSequentialGroup()
                        .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel6)
                            .add(jLabel7))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(cbProuctorCamp, 0, 189, Short.MAX_VALUE)
                            .add(tfLocalitatCamp, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE))))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblImgCamp1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel7Layout.createSequentialGroup()
                .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel7Layout.createSequentialGroup()
                        .add(8, 8, 8)
                        .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel5)
                            .add(tfNomCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel6)
                            .add(tfLocalitatCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel7)
                            .add(cbProuctorCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(jPanel7Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(btCrearCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btBorrarDadesCamp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(lblImgCamp1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout PanelCampsLayout = new org.jdesktop.layout.GroupLayout(PanelCamps);
        PanelCamps.setLayout(PanelCampsLayout);
        PanelCampsLayout.setHorizontalGroup(
            PanelCampsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelCampsLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 260, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PanelCampsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 453, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .add(20, 20, 20))
        );
        PanelCampsLayout.setVerticalGroup(
            PanelCampsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelCampsLayout.createSequentialGroup()
                .add(PanelCampsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(PanelCampsLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 178, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PanelCampsLayout.createSequentialGroup()
                        .add(11, 11, 11)
                        .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(Textos.ADMIN_TITOL_CAMPS, PanelCamps);

        llistaProductes.setModel(Utilitats.getListModel(productes.findProducteEntities()));
        llistaProductes.setCellRenderer(new LabelRenderer());
        llistaProductes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                llistaProductesValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(llistaProductes);

        jLabel8.setText(Textos.ADMIN_PRODUCTE_NOM_PRODUCTE);

        btModificarProducte.setText(Textos.ADMIN_BOTO_MODIFICAR);
        btModificarProducte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btModificarProducteActionPerformed(evt);
            }
        });

        btEliminarProducte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/eliminar_32x32.png"))); // NOI18N
        btEliminarProducte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEliminarProducteActionPerformed(evt);
            }
        });

        jLabel11.setText(Textos.ADMIN_LABEL_DESCRIPCIO);

        lblNomProducte.setText("    ");

        org.jdesktop.layout.GroupLayout jPanel8Layout = new org.jdesktop.layout.GroupLayout(jPanel8);
        jPanel8.setLayout(jPanel8Layout);
        jPanel8Layout.setHorizontalGroup(
            jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel8Layout.createSequentialGroup()
                .add(jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel8)
                    .add(jLabel11)
                    .add(jPanel8Layout.createSequentialGroup()
                        .add(16, 16, 16)
                        .add(btModificarProducte)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btEliminarProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel8Layout.createSequentialGroup()
                        .add(24, 24, 24)
                        .add(lblNomProducte)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 17, Short.MAX_VALUE)
                .add(lblImgProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel8Layout.setVerticalGroup(
            jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel8Layout.createSequentialGroup()
                .add(lblImgProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 147, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
            .add(jPanel8Layout.createSequentialGroup()
                .add(jLabel11)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblNomProducte)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 74, Short.MAX_VALUE)
                .add(jPanel8Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btModificarProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btEliminarProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        jLabel12.setText(Textos.ADMIN_PRODUCTE_NOM_PRODUCTE);

        btCrearProducte.setText(Textos.ADMIN_PRODUCTE_BOTO_CREAR);
        btCrearProducte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCrearProducteActionPerformed(evt);
            }
        });

        btBorrarDadesProducte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/borrar.gif"))); // NOI18N
        btBorrarDadesProducte.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBorrarDadesProducteActionPerformed(evt);
            }
        });

        lblImgProducte1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png"))); // NOI18N
        lblImgProducte1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblImgProducte1MouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel9Layout = new org.jdesktop.layout.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel9Layout.createSequentialGroup()
                .add(jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel9Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jPanel9Layout.createSequentialGroup()
                                .add(btCrearProducte)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(btBorrarDadesProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(tfNomProducte, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)))
                    .add(jLabel12))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblImgProducte1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel9Layout.createSequentialGroup()
                .add(jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel9Layout.createSequentialGroup()
                        .add(8, 8, 8)
                        .add(jLabel12)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfNomProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(70, 70, 70)
                        .add(jPanel9Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(btBorrarDadesProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btCrearProducte, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(lblImgProducte1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 175, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(20, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout PanelProductesLayout = new org.jdesktop.layout.GroupLayout(PanelProductes);
        PanelProductes.setLayout(PanelProductesLayout);
        PanelProductesLayout.setHorizontalGroup(
            PanelProductesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, PanelProductesLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 351, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PanelProductesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(jPanel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jSeparator2)
                    .add(jPanel9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        PanelProductesLayout.setVerticalGroup(
            PanelProductesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelProductesLayout.createSequentialGroup()
                .add(PanelProductesLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(PanelProductesLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(jPanel9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PanelProductesLayout.createSequentialGroup()
                        .add(11, 11, 11)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(Textos.ADMIN_TITOL_PRODUCTES, PanelProductes);

        llistaProductors.setModel(Utilitats.getListModel(productors.findProductorEntities()));
        llistaProductors.setCellRenderer(new LabelRenderer());
        llistaProductors.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                llistaProductorsValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(llistaProductors);

        jLabel9.setText(Textos.ADMIN_PRODUCTOR_NOM_PRODUCTOR);

        btModificarProductor.setText(Textos.ADMIN_BOTO_MODIFICAR);
        btModificarProductor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btModificarProductorActionPerformed(evt);
            }
        });

        btEliminarProductor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/eliminar_32x32.png"))); // NOI18N
        btEliminarProductor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEliminarProductorActionPerformed(evt);
            }
        });

        jLabel13.setText(Textos.ADMIN_LABEL_DESCRIPCIO);

        lblNomProductor.setText("    ");

        org.jdesktop.layout.GroupLayout jPanel10Layout = new org.jdesktop.layout.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel10Layout.createSequentialGroup()
                .add(jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel9)
                    .add(jLabel13)
                    .add(jPanel10Layout.createSequentialGroup()
                        .add(16, 16, 16)
                        .add(btModificarProductor)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btEliminarProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel10Layout.createSequentialGroup()
                        .add(24, 24, 24)
                        .add(lblNomProductor)))
                .addContainerGap(294, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel10Layout.createSequentialGroup()
                .add(jLabel13)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel9)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(lblNomProductor)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 74, Short.MAX_VALUE)
                .add(jPanel10Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btModificarProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btEliminarProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        jLabel14.setText(Textos.ADMIN_PRODUCTOR_NOM_PRODUCTOR);

        btCrearProductor.setText(Textos.ADMIN_PRODUCTOR_BOTO_CREAR);
        btCrearProductor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCrearProductorActionPerformed(evt);
            }
        });

        btBorrarDadesProductor.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/borrar.gif"))); // NOI18N
        btBorrarDadesProductor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBorrarDadesProductorActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel11Layout = new org.jdesktop.layout.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel11Layout.createSequentialGroup()
                .add(jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel11Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jPanel11Layout.createSequentialGroup()
                                .add(btCrearProductor)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .add(btBorrarDadesProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                            .add(tfNomProductor, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)))
                    .add(jLabel14))
                .add(291, 291, 291))
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel11Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jLabel14)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(tfNomProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(70, 70, 70)
                .add(jPanel11Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(btBorrarDadesProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btCrearProductor, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(25, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout PanelProductorLayout = new org.jdesktop.layout.GroupLayout(PanelProductor);
        PanelProductor.setLayout(PanelProductorLayout);
        PanelProductorLayout.setHorizontalGroup(
            PanelProductorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, PanelProductorLayout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 235, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PanelProductorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jSeparator3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 478, Short.MAX_VALUE)
                    .add(jPanel10, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel11, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        PanelProductorLayout.setVerticalGroup(
            PanelProductorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelProductorLayout.createSequentialGroup()
                .add(PanelProductorLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(PanelProductorLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSeparator3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(jPanel11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PanelProductorLayout.createSequentialGroup()
                        .add(11, 11, 11)
                        .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(Textos.ADMIN_TITOL_PRODUCTORS, PanelProductor);

        llistaAbonos.setModel(Utilitats.getListModel(abonos.findAbonoEntities()));
        llistaAbonos.setCellRenderer(new LabelRenderer());
        llistaAbonos.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                llistaAbonosValueChanged(evt);
            }
        });
        jScrollPane4.setViewportView(llistaAbonos);

        jLabel10.setText(Textos.ADMIN_ABONO_NOM_ABONO);

        jLabel15.setText(Textos.ADMIN_ABONO_COMPOSICIO);

        jLabel16.setText(Textos.ADMIN_ABONO_QUANTITAT);

        btModificarAbono.setText(Textos.ADMIN_BOTO_MODIFICAR);
        btModificarAbono.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btModificarAbonoActionPerformed(evt);
            }
        });

        btEliminarAbono.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/eliminar_32x32.png"))); // NOI18N
        btEliminarAbono.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEliminarAbonoActionPerformed(evt);
            }
        });

        lblNomAbono.setText("   ");

        jLabel17.setText(Textos.ADMIN_LABEL_DESCRIPCIO);

        lblComposicioAbono.setText("   ");

        lblQuantitatAbono.setText("   ");

        org.jdesktop.layout.GroupLayout jPanel12Layout = new org.jdesktop.layout.GroupLayout(jPanel12);
        jPanel12.setLayout(jPanel12Layout);
        jPanel12Layout.setHorizontalGroup(
            jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel12Layout.createSequentialGroup()
                .add(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel17)
                    .add(jLabel16)
                    .add(jPanel12Layout.createSequentialGroup()
                        .add(jLabel15)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblComposicioAbono))
                    .add(jPanel12Layout.createSequentialGroup()
                        .add(jLabel10)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblNomAbono))
                    .add(jPanel12Layout.createSequentialGroup()
                        .add(24, 24, 24)
                        .add(lblQuantitatAbono)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 193, Short.MAX_VALUE)
                .add(lblImgAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 161, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(jPanel12Layout.createSequentialGroup()
                .add(9, 9, 9)
                .add(btModificarAbono)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(btEliminarAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(281, Short.MAX_VALUE))
        );
        jPanel12Layout.setVerticalGroup(
            jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel12Layout.createSequentialGroup()
                .add(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel12Layout.createSequentialGroup()
                        .add(jLabel17)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel10)
                            .add(lblNomAbono))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel15)
                            .add(lblComposicioAbono))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jLabel16)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblQuantitatAbono))
                    .add(lblImgAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 9, Short.MAX_VALUE)
                .add(jPanel12Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btModificarAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btEliminarAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );

        jLabel18.setText(Textos.ADMIN_ABONO_NOM_ABONO);

        jLabel19.setText(Textos.ADMIN_ABONO_COMPOSICIO);

        jLabel20.setText(Textos.ADMIN_ABONO_BULTO);

        btCrearAbono.setText(Textos.ADMIN_ABONO_BOTO_CREAR);
        btCrearAbono.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCrearAbonoActionPerformed(evt);
            }
        });

        btBorrarDadesAbono.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/borrar.gif"))); // NOI18N
        btBorrarDadesAbono.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBorrarDadesAbonoActionPerformed(evt);
            }
        });

        lblImgAbono1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png"))); // NOI18N
        lblImgAbono1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lblImgAbono1MouseClicked(evt);
            }
        });

        cbBultoAbono.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForAbonoPaquet()));
        cbBultoAbono.setRenderer(new LabelRenderer());

        jLabel21.setText(Textos.ADMIN_ABONO_QUANTITAT);

        cbUnitatAbono.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForAbonoQuantitat()));
        cbUnitatAbono.setRenderer(new LabelRenderer());

        org.jdesktop.layout.GroupLayout jPanel13Layout = new org.jdesktop.layout.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel13Layout.createSequentialGroup()
                .add(jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel13Layout.createSequentialGroup()
                        .add(21, 21, 21)
                        .add(tfQuantitatAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 97, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cbUnitatAbono, 0, 156, Short.MAX_VALUE))
                    .add(jPanel13Layout.createSequentialGroup()
                        .add(jLabel18)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfNomAbono, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 187, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel13Layout.createSequentialGroup()
                        .add(jLabel20)
                        .add(cbBultoAbono, 0, 197, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel13Layout.createSequentialGroup()
                        .add(jLabel19)
                        .add(5, 5, 5))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel13Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(tfComposicioAbono, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 261, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel21))
                .add(17, 17, 17)
                .add(lblImgAbono1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 160, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(jPanel13Layout.createSequentialGroup()
                .add(9, 9, 9)
                .add(btCrearAbono)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(btBorrarDadesAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(281, Short.MAX_VALUE))
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel13Layout.createSequentialGroup()
                .add(jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel13Layout.createSequentialGroup()
                        .add(8, 8, 8)
                        .add(jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel18)
                            .add(tfNomAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel19)
                        .add(2, 2, 2)
                        .add(tfComposicioAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel20)
                            .add(cbBultoAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel21))
                    .add(lblImgAbono1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 138, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(tfQuantitatAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(cbUnitatAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel13Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btCrearAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btBorrarDadesAbono, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout PanelAbonosLayout = new org.jdesktop.layout.GroupLayout(PanelAbonos);
        PanelAbonos.setLayout(PanelAbonosLayout);
        PanelAbonosLayout.setHorizontalGroup(
            PanelAbonosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelAbonosLayout.createSequentialGroup()
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 298, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PanelAbonosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel12, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jSeparator4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 458, Short.MAX_VALUE)
                    .add(jPanel13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
        PanelAbonosLayout.setVerticalGroup(
            PanelAbonosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelAbonosLayout.createSequentialGroup()
                .add(PanelAbonosLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(PanelAbonosLayout.createSequentialGroup()
                        .addContainerGap()
                        .add(jPanel12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSeparator4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(PanelAbonosLayout.createSequentialGroup()
                        .add(11, 11, 11)
                        .add(jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(Textos.ADMIN_TITOL_ABONOS, PanelAbonos);

        llistaFitos.setModel(Utilitats.getListModel(fitosanitaris.findFitosanitariEntities()));
        llistaFitos.setCellRenderer(new LabelRenderer());
        llistaFitos.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                llistaFitosValueChanged(evt);
            }
        });
        jScrollPane5.setViewportView(llistaFitos);

        jLabel22.setText(Textos.ADMIN_FITOS_NOM_FITOS);

        jLabel23.setText(Textos.ADMIN_FITOS_MATERIA_ACTIVA);

        jLabel24.setText(Textos.ADMIN_FITOS_COMPOSICIO);

        btModificarFitos.setText(Textos.ADMIN_BOTO_MODIFICAR);
        btModificarFitos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btModificarFitosActionPerformed(evt);
            }
        });

        btEliminarFitos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/eliminar_32x32.png"))); // NOI18N
        btEliminarFitos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btEliminarFitosActionPerformed(evt);
            }
        });

        lblNomFitos.setText("   ");

        lblMateriaActivaFitos.setText("   ");

        lblComposicioFitos.setText("   ");

        jLabel25.setText(Textos.ADMIN_FITOS_DOSIS);

        jLabel30.setText(Textos.ADMIN_FITOS_PLAZ_SEG);

        jLabel31.setText(Textos.ADMIN_FITOS_NUM_REG);

        jLabel32.setText(Textos.ADMIN_FITOS_DATA_FI);

        jLabel33.setText(Textos.ADMIN_FITOS_AUTORITZATS);

        taProdAutoritzats.setColumns(14);
        taProdAutoritzats.setEditable(false);
        taProdAutoritzats.setRows(4);
        jScrollPane7.setViewportView(taProdAutoritzats);

        lblDosisFitos.setText("   ");

        lblPlazSegFitos.setText("   ");

        lblNumRegFitos.setText("   ");

        lblDatFiFitos.setText("   ");

        org.jdesktop.layout.GroupLayout jPanel14Layout = new org.jdesktop.layout.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel14Layout.createSequentialGroup()
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel23)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblMateriaActivaFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel24)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblComposicioFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel25)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblDosisFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel22)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblNomFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel30)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblPlazSegFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel31)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblNumRegFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel32)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(lblDatFiFitos))
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(btModificarFitos)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btEliminarFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 112, Short.MAX_VALUE)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(lblImgFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel14Layout.createSequentialGroup()
                        .add(jLabel33)
                        .add(82, 82, 82))
                    .add(jScrollPane7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 177, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel14Layout.createSequentialGroup()
                .add(8, 8, 8)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel22)
                    .add(lblNomFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel23)
                    .add(lblMateriaActivaFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel24)
                    .add(lblComposicioFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel25)
                    .add(lblDosisFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel30)
                    .add(lblPlazSegFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel31)
                    .add(lblNumRegFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel32)
                    .add(lblDatFiFitos))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel14Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(btModificarFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btEliminarFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            .add(jPanel14Layout.createSequentialGroup()
                .add(lblImgFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel33)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        jLabel26.setText(Textos.ADMIN_FITOS_NOM_FITOS);

        jLabel27.setText(Textos.ADMIN_FITOS_MATERIA_ACTIVA);

        jLabel28.setText(Textos.ADMIN_FITOS_COMPOSICIO);

        jLabel29.setText(Textos.ADMIN_FITOS_DOSIS);

        jLabel34.setText(Textos.ADMIN_FITOS_PLAZ_SEG);

        jLabel35.setText(Textos.ADMIN_FITOS_NUM_REG);

        jLabel36.setText(Textos.ADMIN_FITOS_DATA_FI);

        jLabel37.setText(Textos.ADMIN_FITOS_AUTORITZATS);

        taProdAutoFito1.setColumns(14);
        taProdAutoFito1.setRows(4);
        jScrollPane8.setViewportView(taProdAutoFito1);

        btCrearFitos.setText(Textos.ADMIN_FITOS_BOTO_CREAR);
        btCrearFitos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btCrearFitosActionPerformed(evt);
            }
        });

        btBorrarDadesFitos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/borrar.gif"))); // NOI18N
        btBorrarDadesFitos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btBorrarDadesFitosActionPerformed(evt);
            }
        });

        tfPlazSegFitos.setText("0");

        cbUnitatDosisFitos.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForFitosanDisolucio()));
        cbUnitatDosisFitos.setRenderer(new LabelRenderer());

        jLabel38.setText("per");

        cbUnitaDisolucioFitos.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForFitosanDisolucio()));
        cbUnitaDisolucioFitos.setRenderer(new LabelRenderer());

        dcDataFiFito.setDate(GregorianCalendar.getInstance().getTime());

        ftfDosisFitos.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter()));
        ftfDosisFitos.setText("0");

        org.jdesktop.layout.GroupLayout jPanel15Layout = new org.jdesktop.layout.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel15Layout.createSequentialGroup()
                .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jLabel28)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfComposicioFitos, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jLabel27)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfMateriaActFitos, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel15Layout.createSequentialGroup()
                        .add(jLabel26)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfNomFitos, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jLabel34)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfPlazSegFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jLabel35)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(tfNumRegFitos, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE))
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jLabel36)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(dcDataFiFito, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 165, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(btCrearFitos)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(btBorrarDadesFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .add(14, 14, 14)
                .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                        .add(jLabel37)
                        .add(jScrollPane8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 177, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, lblImgFitos1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            .add(jPanel15Layout.createSequentialGroup()
                .add(jLabel29)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(ftfDosisFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 94, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cbUnitatDosisFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel38)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(cbUnitaDisolucioFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(128, 128, 128))
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel15Layout.createSequentialGroup()
                .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(8, 8, 8)
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel26)
                            .add(tfNomFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel27)
                            .add(tfMateriaActFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel28)
                            .add(tfComposicioFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(lblImgFitos1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 107, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel29)
                            .add(ftfDosisFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(cbUnitatDosisFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jLabel38)
                            .add(cbUnitaDisolucioFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel34)
                            .add(tfPlazSegFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jLabel37))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jPanel15Layout.createSequentialGroup()
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel35)
                            .add(tfNumRegFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(jLabel36)
                            .add(dcDataFiFito, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel15Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(btCrearFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(btBorrarDadesFitos, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 40, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(jScrollPane8))
                .addContainerGap())
        );

        org.jdesktop.layout.GroupLayout PanelFitosanitarisLayout = new org.jdesktop.layout.GroupLayout(PanelFitosanitaris);
        PanelFitosanitaris.setLayout(PanelFitosanitarisLayout);
        PanelFitosanitarisLayout.setHorizontalGroup(
            PanelFitosanitarisLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelFitosanitarisLayout.createSequentialGroup()
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 298, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PanelFitosanitarisLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel14, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jSeparator5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
                    .add(jPanel15, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        PanelFitosanitarisLayout.setVerticalGroup(
            PanelFitosanitarisLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(PanelFitosanitarisLayout.createSequentialGroup()
                .add(PanelFitosanitarisLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(PanelFitosanitarisLayout.createSequentialGroup()
                        .add(11, 11, 11)
                        .add(jScrollPane5))
                    .add(org.jdesktop.layout.GroupLayout.LEADING, PanelFitosanitarisLayout.createSequentialGroup()
                        .add(jPanel14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jSeparator5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(2, 2, 2)
                        .add(jPanel15, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 292, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab(Textos.ADMIN_TITOL_FITOSANITARIS, PanelFitosanitaris);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(btMenu1)
                    .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jTabbedPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 589, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(btMenu1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMenu1ActionPerformed
        if (menu != null) {
            menu.setVisible(true);
            this.setVisible(false);
        }
}//GEN-LAST:event_btMenu1ActionPerformed

    private void llistaCampsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_llistaCampsValueChanged
        Camp campSel = (Camp) llistaCamps.getSelectedValue();
        if (campSel != null) {
            btEliminarCamp.setEnabled(true);
            btModificarCamp.setEnabled(true);
            String nom = campSel.getNom();
            if (nom != null) {
                lblNomCamp.setText(nom);
            }
            String localitat = campSel.getLocalitat();
            if (localitat != null) {
                lblLocalitatCamp.setText(localitat);
            }
            Productor productor = campSel.getProductorId();
            if (productor != null) {
                lblProductorCamp.setText(productor.getNom());
            }
            byte[] imatge = campSel.getImg();
            if (imatge != null) {
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgCamp, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_llistaCampsValueChanged

    private void btEliminarCampActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEliminarCampActionPerformed
        Camp campSel = (Camp) llistaCamps.getSelectedValue();
        if (campSel != null) {
            Object[] options = {Textos.COMU_SI, Textos.COMU_NO};
            int n = JOptionPane.showOptionDialog(this, Textos.ADMIN_WARNING_ELIMINAR_CAMP, Textos.COMU_AVIS, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
            if (n == 0) {
                try {
                    camps.destroy(campSel.getId());
                } catch (IllegalOrphanException ex) {
                    JOptionPane.showMessageDialog(this, Textos.ADMIN_ERROR_ELIMINAR_CAMP, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                }
                llistaCamps.clearSelection();
                updateCamps();
            }
        }
    }//GEN-LAST:event_btEliminarCampActionPerformed

    private void btModificarCampActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btModificarCampActionPerformed
        Camp campSel = (Camp) llistaCamps.getSelectedValue();
        //Si hi ha un cmao seleccionat
        if (campSel != null) {
            this.camp = campSel;
            String nom = campSel.getNom();
            if (nom != null) {
                tfNomCamp.setText(nom);
            }
            String localitat = campSel.getLocalitat();
            if (localitat != null) {
                tfLocalitatCamp.setText(localitat);
            }
            Productor productor = campSel.getProductorId();
            if (productor != null) {
                cbProuctorCamp.setSelectedItem(productor);
            }
            byte[] imatge = campSel.getImg();
            if (imatge != null) {
                this.imgCamp = imatge;
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgCamp1, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btCrearCamp.setText(Textos.ADMIN_CAMP_BOTO_GUARDAR);
        }
    }//GEN-LAST:event_btModificarCampActionPerformed

    private void lblImgCamp1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblImgCamp1MouseClicked
        if (fc == null) {
            fc = new JFileChooser();
        }
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            FileInputStream fis = null;
            try {
                File file = fc.getSelectedFile();
                fis = new FileInputStream(file);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                for (int readNum; (readNum = fis.read(buf)) != -1;) {
                    bos.write(buf, 0, readNum);
                }
                imgCamp = bos.toByteArray();
                Utilitats.adabtarImatgeAlLabel(lblImgCamp1, imgCamp);
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_NO_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_NO_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_FORMAT_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
}//GEN-LAST:event_lblImgCamp1MouseClicked

    private void btBorrarDadesCampActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBorrarDadesCampActionPerformed
        this.camp = null;
        updateCamps();
}//GEN-LAST:event_btBorrarDadesCampActionPerformed

    private void btCrearCampActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCrearCampActionPerformed
        String nom = tfNomCamp.getText();
        String localitat = tfLocalitatCamp.getText();
        Productor productor = (Productor) cbProuctorCamp.getSelectedItem();
        if (imgCamp == null) {
            FileInputStream fis = null;
            try {
                File file = new File(getClass().getResource("/vistas/textImg/Camp0.png").getFile());
                fis = new FileInputStream(file);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                for (int readNum; (readNum = fis.read(buf)) != -1;) {
                    bos.write(buf, 0, readNum);
                }
                imgCamp = bos.toByteArray();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException ex) {
                        Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
        if ((!nom.equals("")) && (productor != null)) {
            if (this.camp == null) { //ES CN CAMPNOU
                Camp nouCamp = new Camp();
                nouCamp.setNom(nom);
                nouCamp.setProductorId(productor);
                if (localitat != null) {
                    nouCamp.setLocalitat(localitat);
                }
                if (imgCamp != null) {
                    nouCamp.setImg(imgCamp);
                }
                camps.create(nouCamp);
            } else { // ES MODIFICA UN CAMP EXISTENT
                this.camp.setNom(nom);
                this.camp.setProductorId(productor);
                if (localitat != null) {
                    this.camp.setLocalitat(localitat);
                }
                if (imgCamp != null) {
                    this.camp.setImg(imgCamp);
                }
                try {
                    camps.edit(this.camp);
                } catch (IllegalOrphanException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (Exception ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btBorrarDadesCampActionPerformed(evt);

        } else {
            JOptionPane.showMessageDialog(this, Textos.ADMIN_CAMP_INFO_INTRODUEIX_NOM_I_PRODUCTOR, "", JOptionPane.WARNING_MESSAGE);
        }
}//GEN-LAST:event_btCrearCampActionPerformed

    private void llistaProductesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_llistaProductesValueChanged
        Producte producteSel = (Producte) llistaProductes.getSelectedValue();
        if (producteSel != null) {
            btModificarProducte.setEnabled(true);
            btEliminarProducte.setEnabled(true);
            String nom = producteSel.getNom();
            if (nom != null) {
                lblNomProducte.setText(nom);
            }
            byte[] imatge = producteSel.getImg();
            if (imatge != null) {
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgProducte, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_llistaProductesValueChanged

    private void btModificarProducteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btModificarProducteActionPerformed
        Producte producteSel = (Producte) llistaProductes.getSelectedValue();
        if (producteSel != null) {
            this.producte = producteSel;
            String nom = producteSel.getNom();
            if (nom != null) {
                tfNomProducte.setText(nom);
            }
            byte[] imatge = producteSel.getImg();
            if (imatge != null) {
                this.imgProducte = imatge;
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgProducte1, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btCrearProducte.setText(Textos.ADMIN_PRODUCTE_BOTO_GUARDAR);
        }
    }//GEN-LAST:event_btModificarProducteActionPerformed

    private void btEliminarProducteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEliminarProducteActionPerformed
        Producte producteSel = (Producte) llistaProductes.getSelectedValue();
        if (producteSel != null) {
            Object[] options = {Textos.COMU_SI, Textos.COMU_NO};
            int n = JOptionPane.showOptionDialog(this, Textos.ADMIN_WARNING_ELIMINAR_PRODUCTE, Textos.COMU_AVIS, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
            if (n == 0) {
                try {
                    productes.destroy(producteSel.getId());
                } catch (IllegalOrphanException ex) {
                    JOptionPane.showMessageDialog(this, Textos.ADMIN_ERROR_ELIMINAR_PRODUCTE, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                }
                llistaProductes.clearSelection();
                updateProductes();
            }
        }
    }//GEN-LAST:event_btEliminarProducteActionPerformed

    private void btCrearProducteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCrearProducteActionPerformed
        String nom = tfNomProducte.getText();
        if (imgProducte == null) {
            FileInputStream fis = null;
            try {
                File file = new File(getClass().getResource("/vistas/textImg/Foto.png").getFile());
                fis = new FileInputStream(file);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                for (int readNum; (readNum = fis.read(buf)) != -1;) {
                    bos.write(buf, 0, readNum);
                }
                imgProducte = bos.toByteArray();
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (IOException ex) {
                        Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        }
        if (!nom.equals("")) {
            if (this.producte == null) { //ES un Producte nou
                Producte nouProducte = new Producte();
                nouProducte.setNom(nom);
                if (imgProducte != null) {
                    nouProducte.setImg(imgProducte);
                }
                productes.create(nouProducte);
            } else { // ES MODIFICA UN Producte EXISTENT
                this.producte.setNom(nom);
                if (imgProducte != null) {
                    this.producte.setImg(imgProducte);
                }
                try {
                    productes.edit(this.producte);
                } catch (IllegalOrphanException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (Exception ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btBorrarDadesProducteActionPerformed(evt);

        } else {
            JOptionPane.showMessageDialog(this, Textos.ADMIN_PRODUCTE_INFO_INTRODUEIX_NOM, "", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btCrearProducteActionPerformed

    private void btBorrarDadesProducteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBorrarDadesProducteActionPerformed
        this.producte = null;
        updateProductes();
    }//GEN-LAST:event_btBorrarDadesProducteActionPerformed

    private void lblImgProducte1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblImgProducte1MouseClicked
        if (fc == null) {
            fc = new JFileChooser();
        }
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            FileInputStream fis = null;
            try {
                File file = fc.getSelectedFile();
                fis = new FileInputStream(file);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                for (int readNum; (readNum = fis.read(buf)) != -1;) {
                    bos.write(buf, 0, readNum);
                }
                imgProducte = bos.toByteArray();
                Utilitats.adabtarImatgeAlLabel(lblImgProducte1, imgProducte);
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_NO_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_NO_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_FORMAT_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_lblImgProducte1MouseClicked

    private void llistaProductorsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_llistaProductorsValueChanged
        Productor productorSel = (Productor) llistaProductors.getSelectedValue();
        if (productorSel != null) {
            btModificarProductor.setEnabled(true);
            btEliminarProductor.setEnabled(true);
            String nom = productorSel.getNom();
            if (nom != null) {
                lblNomProductor.setText(nom);
            }
        }
    }//GEN-LAST:event_llistaProductorsValueChanged

    private void btModificarProductorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btModificarProductorActionPerformed
        Productor productorSel = (Productor) llistaProductors.getSelectedValue();
        if (productorSel != null) {
            this.productor = productorSel;
            String nom = productorSel.getNom();
            if (nom != null) {
                tfNomProductor.setText(nom);
            }
            btCrearProductor.setText(Textos.ADMIN_PRODUCTOR_BOTO_GUARDAR);
        }
    }//GEN-LAST:event_btModificarProductorActionPerformed

    private void btEliminarProductorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEliminarProductorActionPerformed
        Productor productorSel = (Productor) llistaProductors.getSelectedValue();
        if (productorSel != null) {
            Object[] options = {Textos.COMU_SI, Textos.COMU_NO};
            int n = JOptionPane.showOptionDialog(this, Textos.ADMIN_WARNING_ELIMINAR_PRODUCTOR, Textos.COMU_AVIS, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
            if (n == 0) {
                try {
                    productors.destroy(productorSel.getId());
                } catch (IllegalOrphanException ex) {
                    JOptionPane.showMessageDialog(this, Textos.ADMIN_ERROR_ELIMINAR_PRODUCTOR, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                }
                llistaProductors.clearSelection();
                updateProductors();
            }
        }
    }//GEN-LAST:event_btEliminarProductorActionPerformed

    private void btCrearProductorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCrearProductorActionPerformed
        String nom = tfNomProductor.getText();
        if (!nom.equals("")) {
            if (this.productor == null) { //ES un Productor nou
                Productor nouProductor = new Productor();
                nouProductor.setNom(nom);
                productors.create(nouProductor);
            } else { // ES MODIFICA UN Productor EXISTENT
                this.productor.setNom(nom);
                try {
                    productors.edit(this.productor);
                } catch (IllegalOrphanException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (Exception ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btBorrarDadesProductorActionPerformed(evt);

        } else {
            JOptionPane.showMessageDialog(this, Textos.ADMIN_PRODUCTOR_INFO_INTRODUEIX_NOM, "", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btCrearProductorActionPerformed

    private void btBorrarDadesProductorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBorrarDadesProductorActionPerformed
        this.productor = null;
        updateProductors();
    }//GEN-LAST:event_btBorrarDadesProductorActionPerformed

    private void llistaAbonosValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_llistaAbonosValueChanged
        Abono abonoSel = (Abono) llistaAbonos.getSelectedValue();
        if (abonoSel != null) {
            btModificarAbono.setEnabled(true);
            btEliminarAbono.setEnabled(true);
            String nom = abonoSel.getNom();
            if (nom != null) {
                lblNomAbono.setText(nom);
            }
            String composicio = abonoSel.getComposicio();
            if (composicio != null) {
                lblComposicioAbono.setText(composicio);
            }
            String bulto = abonoSel.getUnitatsPaquet().getNom();
            String quantitat = String.valueOf(abonoSel.getQuantitatPaquet());
            String unitat = abonoSel.getUnitatsQuantitat().getNom();
            if ((bulto != null) && (quantitat != null) && (unitat != null)) {
                lblQuantitatAbono.setText(bulto + " de " + quantitat + " " + unitat);
            }
            byte[] imatge = abonoSel.getImg();
            if (imatge != null) {
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgAbono, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_llistaAbonosValueChanged

    private void btModificarAbonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btModificarAbonoActionPerformed
        Abono abonoSel = (Abono) llistaAbonos.getSelectedValue();
        if (abonoSel != null) {
            this.abono = abonoSel;
            String nom = abonoSel.getNom();
            if (nom != null) {
                tfNomAbono.setText(nom);
            }
            String composicio = abonoSel.getComposicio();
            if (composicio != null) {
                tfComposicioAbono.setText(composicio);
            }
            UnitatsMesura bulto = abonoSel.getUnitatsPaquet();
            if (bulto != null) {
                cbBultoAbono.setSelectedItem(bulto);
            }
            String quantitat = String.valueOf(abonoSel.getQuantitatPaquet());
            if (quantitat != null) {
                tfQuantitatAbono.setText(quantitat);
            }
            UnitatsMesura unitat = abonoSel.getUnitatsQuantitat();
            if (unitat != null) {
                cbUnitatAbono.setSelectedItem(unitat);
            }
            byte[] imatge = abonoSel.getImg();
            if (imatge != null) {
                this.imgAbono = imatge;
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgAbono1, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_btModificarAbonoActionPerformed

    private void btEliminarAbonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEliminarAbonoActionPerformed
        Abono abonoSel = (Abono) llistaAbonos.getSelectedValue();
        if (abonoSel != null) {
            Object[] options = {Textos.COMU_SI, Textos.COMU_NO};
            int n = JOptionPane.showOptionDialog(this, Textos.ADMIN_WARNING_ELIMINAR_ABONO, Textos.COMU_AVIS, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
            if (n == 0) {
                try {
                    abonos.destroy(abonoSel.getId());
                } catch (IllegalOrphanException ex) {
                    JOptionPane.showMessageDialog(this, Textos.ADMIN_ERROR_ELIMINAR_ABONO, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                }
                llistaAbonos.clearSelection();
                updateAbonos();
            }
        }
    }//GEN-LAST:event_btEliminarAbonoActionPerformed

    private void btCrearAbonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCrearAbonoActionPerformed
        String nom = tfNomAbono.getText();
        UnitatsMesura bulto = (UnitatsMesura) cbBultoAbono.getSelectedItem();
        String quantitatString = tfQuantitatAbono.getText();
        UnitatsMesura unitat = (UnitatsMesura) cbUnitatAbono.getSelectedItem();
        if ((!nom.equals("")) && (bulto != null) && (!quantitatString.equals("")) && (unitat != null)) {
            if (imgAbono == null) {
                FileInputStream fis = null;
                try {
                    File file = new File(getClass().getResource("/vistas/textImg/Foto.png").getFile());
                    fis = new FileInputStream(file);
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    for (int readNum; (readNum = fis.read(buf)) != -1;) {
                        bos.write(buf, 0, readNum);
                    }
                    imgAbono = bos.toByteArray();
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (IOException ex) {
                            Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
            if (this.abono == null) {  //Es un Abono Nou
                Abono nouAbono = new Abono();
                nouAbono.setNom(nom);
                nouAbono.setUnitatsPaquet(bulto);
                nouAbono.setQuantitatPaquet(Integer.valueOf(quantitatString));
                nouAbono.setUnitatsQuantitat(unitat);
                nouAbono.setComposicio(tfComposicioAbono.getText());
                if (imgAbono != null) {
                    nouAbono.setImg(imgAbono);
                }
                abonos.create(nouAbono);
            } else {   // Es un modifcia un abono existent
                this.abono.setNom(nom);
                this.abono.setUnitatsPaquet(bulto);
                this.abono.setQuantitatPaquet(Integer.valueOf(quantitatString));
                this.abono.setUnitatsQuantitat(unitat);
                this.abono.setComposicio(tfComposicioAbono.getText());
                if (imgAbono != null) {
                    this.abono.setImg(imgAbono);
                }
                try {
                    abonos.edit(this.abono);
                } catch (IllegalOrphanException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (Exception ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btBorrarDadesAbonoActionPerformed(evt);

        } else {
            JOptionPane.showMessageDialog(this, Textos.ADMIN_ABONO_INFO_INTRODUEIX_NOM_BULTO_QUANTITAT, "", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btCrearAbonoActionPerformed

    private void btBorrarDadesAbonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBorrarDadesAbonoActionPerformed
        this.abono = null;
        updateAbonos();
    }//GEN-LAST:event_btBorrarDadesAbonoActionPerformed

    private void lblImgAbono1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lblImgAbono1MouseClicked
        if (fc == null) {
            fc = new JFileChooser();
        }
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            FileInputStream fis = null;
            try {
                File file = fc.getSelectedFile();
                fis = new FileInputStream(file);
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                byte[] buf = new byte[1024];
                for (int readNum; (readNum = fis.read(buf)) != -1;) {
                    bos.write(buf, 0, readNum);
                }
                imgAbono = bos.toByteArray();
                Utilitats.adabtarImatgeAlLabel(lblImgAbono1, imgAbono);
            } catch (FileNotFoundException ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_NO_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_NO_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_FORMAT_ARXIU, "", JOptionPane.ERROR_MESSAGE);
                Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    fis.close();
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_lblImgAbono1MouseClicked

    private void llistaFitosValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_llistaFitosValueChanged
        Fitosanitari fitosSel = (Fitosanitari) llistaFitos.getSelectedValue();
        if (fitosSel != null) {
            btModificarFitos.setEnabled(true);
            btEliminarFitos.setEnabled(true);
            String nom = fitosSel.getNomComercial();
            if (nom != null) {
                lblNomFitos.setText(nom);
            }
            String materia = fitosSel.getMateriaActiva();
            if (materia != null) {
                lblMateriaActivaFitos.setText(materia);
            }
            String composicio = fitosSel.getComposicio();
            if (composicio != null) {
                lblComposicioFitos.setText(composicio);
            }
            float dosis = fitosSel.getDosis();
            String unitatDosis = fitosSel.getUnitatsDosis().getNom();
            String unitatDisol = fitosSel.getUnitatsDisolucio().getNom();
            lblDosisFitos.setText(dosis + " " + unitatDosis + " per " + unitatDisol);
            int plazSeg = fitosSel.getPlazSegurDies();
            lblPlazSegFitos.setText(plazSeg + " dies");
            String numReg = fitosSel.getNumRegistre();
            if (numReg != null) {
                lblNumRegFitos.setText(numReg);
            }
            Date dataFi = fitosSel.getDataFiAutoritzacio();
            if (dataFi != null) {
                lblDatFiFitos.setText(Configuracio.sdf_ddMMyyyy.format(dataFi));
            }
            String prodAuto = fitosSel.getProducAutortizats();
            if (prodAuto != null) {
                taProdAutoritzats.setText(prodAuto);
            }
            byte[] imatge = fitosSel.getImg();
            if (imatge != null) {
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgFitos, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }//GEN-LAST:event_llistaFitosValueChanged

    private void btModificarFitosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btModificarFitosActionPerformed
        Fitosanitari fitosSel = (Fitosanitari) llistaFitos.getSelectedValue();
        if (fitosSel != null) {
            this.fitosanitari = fitosSel;
            String nom = fitosSel.getNomComercial();
            if (nom != null) {
                tfNomFitos.setText(nom);
            }
            String materia = fitosSel.getMateriaActiva();
            if (materia != null) {
                tfMateriaActFitos.setText(materia);
            }
            String composicio = fitosSel.getComposicio();
            if (composicio != null) {
                tfComposicioFitos.setText(composicio);
            }
            float dosis = fitosSel.getDosis();
            ftfDosisFitos.setText(String.valueOf(dosis));
            UnitatsMesura unitatDosis = fitosSel.getUnitatsDosis();
            if (unitatDosis != null) {
                cbUnitatDosisFitos.setSelectedItem(unitatDosis);
            }
            UnitatsMesura unitatDisol = fitosSel.getUnitatsDisolucio();
            if (unitatDisol != null) {
                cbUnitaDisolucioFitos.setSelectedItem(unitatDisol);
            }
            int plazSeg = fitosSel.getPlazSegurDies();
            tfPlazSegFitos.setText(plazSeg + "");
            String numReg = fitosSel.getNumRegistre();
            if (numReg != null) {
                tfNumRegFitos.setText(numReg);
            }
            Date dataFi = fitosSel.getDataFiAutoritzacio();
            if (dataFi != null) {
                dcDataFiFito.setDate(dataFi);
            }
            String prodAuto = fitosSel.getProducAutortizats();
            if (prodAuto != null) {
                taProdAutoFito1.setText(prodAuto);
            }
            byte[] imatge = fitosSel.getImg();
            if (imatge != null) {
                this.imgFitos = imatge;
                try {
                    Utilitats.adabtarImatgeAlLabel(lblImgFitos1, imatge);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btCrearFitos.setText(Textos.ADMIN_FITOS_BOTO_GUARDAR);
        }
    }//GEN-LAST:event_btModificarFitosActionPerformed

    private void btEliminarFitosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btEliminarFitosActionPerformed
        Fitosanitari fitosSel = (Fitosanitari) llistaFitos.getSelectedValue();
        if (fitosSel != null) {
            Object[] options = {Textos.COMU_SI, Textos.COMU_NO};
            int n = JOptionPane.showOptionDialog(this, Textos.ADMIN_WARNING_ELIMINAR_FITOS, Textos.COMU_AVIS, JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1]);
            if (n == 0) {
                try {
                    fitosanitaris.destroy(fitosSel.getId());
                } catch (IllegalOrphanException ex) {
                    JOptionPane.showMessageDialog(this, Textos.ADMIN_ERROR_ELIMINAR_FITOS, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                }
                llistaFitos.clearSelection();
                updateFitos();
            }
        }
    }//GEN-LAST:event_btEliminarFitosActionPerformed

    private void btCrearFitosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btCrearFitosActionPerformed
        String nom = tfNomFitos.getText();
        String materiaAct = tfMateriaActFitos.getText();
        String dosisString = ftfDosisFitos.getText();
        String plazSegString = tfPlazSegFitos.getText();
        UnitatsMesura unitatDosis = (UnitatsMesura) cbUnitatDosisFitos.getSelectedItem();
        UnitatsMesura unitatDisol = (UnitatsMesura) cbUnitaDisolucioFitos.getSelectedItem();
        if ((!nom.equals("")) && (!materiaAct.equals("")) && (!dosisString.equals("0")) && (unitatDosis != null) && (unitatDisol != null)) {
            if (imgFitos == null) {
                FileInputStream fis = null;
                try {
                    File file = new File(getClass().getResource("/vistas/textImg/Foto.png").getFile());
                    fis = new FileInputStream(file);
                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
                    byte[] buf = new byte[1024];
                    for (int readNum; (readNum = fis.read(buf)) != -1;) {
                        bos.write(buf, 0, readNum);
                    }
                    imgFitos = bos.toByteArray();
                } catch (FileNotFoundException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    if (fis != null) {
                        try {
                            fis.close();
                        } catch (IOException ex) {
                            Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                        }
                    }
                }
            }
            if (this.fitosanitari == null) { // Es un Fitos Nou
                Fitosanitari nouFitos = new Fitosanitari();
                nouFitos.setNomComercial(nom);
                nouFitos.setMateriaActiva(materiaAct);
                nouFitos.setComposicio(tfComposicioFitos.getText());
                nouFitos.setDosis(Float.parseFloat(dosisString));
                nouFitos.setUnitatsDosis(unitatDosis);
                nouFitos.setUnitatsDisolucio(unitatDisol);
                nouFitos.setPlazSegurDies(Integer.parseInt(tfPlazSegFitos.getText()));
                nouFitos.setDataFiAutoritzacio(dcDataFiFito.getDate());
                nouFitos.setNumRegistre(tfNumRegFitos.getText());
                nouFitos.setProducAutortizats(taProdAutoFito1.getText());
                if (imgFitos != null) {
                    nouFitos.setImg(imgFitos);
                }
                fitosanitaris.create(nouFitos);
            } else {  // Es modific un fitos existent
                this.fitosanitari.setNomComercial(nom);
                this.fitosanitari.setMateriaActiva(materiaAct);
                this.fitosanitari.setComposicio(tfComposicioFitos.getText());
                this.fitosanitari.setDosis(Float.parseFloat(dosisString));
                this.fitosanitari.setUnitatsDosis(unitatDosis);
                this.fitosanitari.setUnitatsDisolucio(unitatDisol);
                this.fitosanitari.setPlazSegurDies(Integer.parseInt(tfPlazSegFitos.getText()));
                this.fitosanitari.setDataFiAutoritzacio(dcDataFiFito.getDate());
                this.fitosanitari.setNumRegistre(tfNumRegFitos.getText());
                this.fitosanitari.setProducAutortizats(taProdAutoFito1.getText());
                if (imgFitos != null) {
                    this.fitosanitari.setImg(imgCamp);
                }
                try {
                    fitosanitaris.edit(this.fitosanitari);
                } catch (IllegalOrphanException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (NonexistentEntityException ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                    JOptionPane.showMessageDialog(this, Textos.COMU_ERROR_BASE_DADES, "", JOptionPane.ERROR_MESSAGE);
                } catch (Exception ex) {
                    Logger.getLogger(Administrar.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
            btBorrarDadesFitosActionPerformed(evt);
            
        } else {
            JOptionPane.showMessageDialog(this, Textos.ADMIN_FITOS_INFO_INTRODUEIX_NOM_MATERIA_DOSIS_PLAZ, "", JOptionPane.WARNING_MESSAGE);
        }
    }//GEN-LAST:event_btCrearFitosActionPerformed

    private void btBorrarDadesFitosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btBorrarDadesFitosActionPerformed
        this.fitosanitari = null;
        updateFitos();
    }//GEN-LAST:event_btBorrarDadesFitosActionPerformed

    private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jTabbedPane1StateChanged
        update(null, null);
    }//GEN-LAST:event_jTabbedPane1StateChanged

    public void updateProductes() {
        Producte producte = (Producte) llistaProductes.getSelectedValue();
        llistaProductes.setModel(getListModel(productes.findProducteEntitiesAZ()));
        if (producte != null) {
            llistaProductes.setSelectedValue(producte, true);
        }else{
            btModificarProducte.setEnabled(false);
            btEliminarProducte.setEnabled(false);
            lblNomProducte.setText("");
            lblImgProducte.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
            imgProducte = null;
        }
        this.producte = null;
        tfNomProducte.setText("");
        imgProducte = null;
        lblImgProducte1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
        btCrearProducte.setText(Textos.ADMIN_PRODUCTE_BOTO_CREAR);
    }

    public void updateCamps() {
        Camp camp = (Camp) llistaCamps.getSelectedValue();
        llistaCamps.setModel(getListModel(camps.findCampEntitiesAZ()));
        if (camp != null) {
            llistaCamps.setSelectedValue(camp, true);
        }else{
            btModificarCamp.setEnabled(false);
            btEliminarCamp.setEnabled(false);
            lblNomCamp.setText("");
            lblLocalitatCamp.setText("");
            lblProductorCamp.setText("");
            lblImgCamp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
            imgCamp = null;
        }
        this.camp = null;
        tfNomCamp.setText("");
        tfLocalitatCamp.setText("");
        btCrearCamp.setText(Textos.ADMIN_CAMP_BOTO_CREAR);
        lblImgCamp1.setIcon(new ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
        cbProuctorCamp.setModel(Utilitats.getComboBoxModel(productors.findProductorEntitiesAZ()));
    }

    public void updateProductors() {
        Productor productor = (Productor) llistaProductors.getSelectedValue();
        llistaProductors.setModel(getListModel(productors.findProductorEntitiesAZ()));
        if (productor != null) {
            llistaProductors.setSelectedValue(productor, true);
        }else{
            btModificarProductor.setEnabled(false);
            btEliminarProductor.setEnabled(false);
            lblNomProductor.setText("");
        }
        this.productor = null;
        tfNomProductor.setText("");
        btCrearProductor.setText(Textos.ADMIN_PRODUCTOR_BOTO_CREAR);
    }

    public void updateAbonos() {
        Abono abono = (Abono) llistaAbonos.getSelectedValue();
        llistaAbonos.setModel(getListModel(abonos.findAbonoEntities()));
        if (abono != null) {
            llistaAbonos.setSelectedValue(abono, true);
        }else{
            btModificarAbono.setEnabled(false);
            btEliminarAbono.setEnabled(false);
            lblNomAbono.setText("");
            lblComposicioAbono.setText("");
            lblQuantitatAbono.setText("");
            lblImgAbono.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
            imgAbono = null;
        }
        this.abono = null;
        tfNomAbono.setText("");
        tfComposicioAbono.setText("");
        tfQuantitatAbono.setText("");
        cbBultoAbono.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForAbonoPaquet()));
        cbUnitatAbono.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForAbonoQuantitat()));
        imgAbono = null;
        lblImgAbono1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
        btCrearAbono.setText(Textos.ADMIN_ABONO_BOTO_CREAR);
    }

    public void updateFitos() {
        Fitosanitari fitosanitari = (Fitosanitari) llistaFitos.getSelectedValue();
        llistaFitos.setModel(Utilitats.getListModel(fitosanitaris.findFitosanitariEntities()));
        if (fitosanitari != null) {
            llistaFitos.setSelectedValue(fitosanitari, true);
        }else{
            btModificarFitos.setEnabled(false);
            btEliminarFitos.setEnabled(false);
            lblNomFitos.setText("");
            lblMateriaActivaFitos.setText("");
            lblComposicioFitos.setText("");
            lblDosisFitos.setText("");
            lblPlazSegFitos.setText("");
            lblNumRegFitos.setText("");
            lblDatFiFitos.setText("");
            lblImgFitos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
            this.imgFitos = null;
        }
        this.fitosanitari = null;
        tfNomFitos.setText("");
        tfMateriaActFitos.setText("");
        tfComposicioFitos.setText("");
        ftfDosisFitos.setText("0");
        cbUnitatDosisFitos.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForFitosanDosis()));
        cbUnitaDisolucioFitos.setModel(Utilitats.getComboBoxModel(unitats.findUnitatsMesuraEntitiesForFitosanDisolucio()));
        tfPlazSegFitos.setText("0");
        tfNumRegFitos.setText("");
        dcDataFiFito.setDate(new Date());
        taProdAutoFito1.setText("");
        imgFitos = null;
        lblImgFitos1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/vistas/textImg/Foto.png")));
        btCrearFitos.setText(Textos.ADMIN_FITOS_BOTO_CREAR);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelAbonos;
    private javax.swing.JPanel PanelCamps;
    private javax.swing.JPanel PanelFitosanitaris;
    private javax.swing.JPanel PanelProductes;
    private javax.swing.JPanel PanelProductor;
    private javax.swing.JButton btBorrarDadesAbono;
    private javax.swing.JButton btBorrarDadesCamp;
    private javax.swing.JButton btBorrarDadesFitos;
    private javax.swing.JButton btBorrarDadesProducte;
    private javax.swing.JButton btBorrarDadesProductor;
    private javax.swing.JButton btCrearAbono;
    private javax.swing.JButton btCrearCamp;
    private javax.swing.JButton btCrearFitos;
    private javax.swing.JButton btCrearProducte;
    private javax.swing.JButton btCrearProductor;
    private javax.swing.JButton btEliminarAbono;
    private javax.swing.JButton btEliminarCamp;
    private javax.swing.JButton btEliminarFitos;
    private javax.swing.JButton btEliminarProducte;
    private javax.swing.JButton btEliminarProductor;
    private javax.swing.JButton btMenu1;
    private javax.swing.JButton btModificarAbono;
    private javax.swing.JButton btModificarCamp;
    private javax.swing.JButton btModificarFitos;
    private javax.swing.JButton btModificarProducte;
    private javax.swing.JButton btModificarProductor;
    private javax.swing.JComboBox cbBultoAbono;
    private javax.swing.JComboBox cbProuctorCamp;
    private javax.swing.JComboBox cbUnitaDisolucioFitos;
    private javax.swing.JComboBox cbUnitatAbono;
    private javax.swing.JComboBox cbUnitatDosisFitos;
    private com.toedter.calendar.JDateChooser dcDataFiFito;
    private javax.swing.JFormattedTextField ftfDosisFitos;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JLabel lblComposicioAbono;
    private javax.swing.JLabel lblComposicioFitos;
    private javax.swing.JLabel lblDatFiFitos;
    private javax.swing.JLabel lblDosisFitos;
    private javax.swing.JLabel lblImgAbono;
    private javax.swing.JLabel lblImgAbono1;
    private javax.swing.JLabel lblImgCamp;
    private javax.swing.JLabel lblImgCamp1;
    private javax.swing.JLabel lblImgFitos;
    private javax.swing.JLabel lblImgFitos1;
    private javax.swing.JLabel lblImgProducte;
    private javax.swing.JLabel lblImgProducte1;
    private javax.swing.JLabel lblLocalitatCamp;
    private javax.swing.JLabel lblMateriaActivaFitos;
    private javax.swing.JLabel lblNomAbono;
    private javax.swing.JLabel lblNomCamp;
    private javax.swing.JLabel lblNomFitos;
    private javax.swing.JLabel lblNomProducte;
    private javax.swing.JLabel lblNomProductor;
    private javax.swing.JLabel lblNumRegFitos;
    private javax.swing.JLabel lblPlazSegFitos;
    private javax.swing.JLabel lblProductorCamp;
    private javax.swing.JLabel lblQuantitatAbono;
    private javax.swing.JList llistaAbonos;
    private javax.swing.JList llistaCamps;
    private javax.swing.JList llistaFitos;
    private javax.swing.JList llistaProductes;
    private javax.swing.JList llistaProductors;
    private javax.swing.JTextArea taProdAutoFito1;
    private javax.swing.JTextArea taProdAutoritzats;
    private javax.swing.JTextField tfComposicioAbono;
    private javax.swing.JTextField tfComposicioFitos;
    private javax.swing.JTextField tfLocalitatCamp;
    private javax.swing.JTextField tfMateriaActFitos;
    private javax.swing.JTextField tfNomAbono;
    private javax.swing.JTextField tfNomCamp;
    private javax.swing.JTextField tfNomFitos;
    private javax.swing.JTextField tfNomProducte;
    private javax.swing.JTextField tfNomProductor;
    private javax.swing.JTextField tfNumRegFitos;
    private javax.swing.JTextField tfPlazSegFitos;
    private javax.swing.JTextField tfQuantitatAbono;
    // End of variables declaration//GEN-END:variables

    private DefaultListModel getListModel(List llista) {
        DefaultListModel modelP = new DefaultListModel();
        for (int i = 0; i < llista.size(); i++) {
            modelP.addElement(llista.get(i));
        }
        return modelP;
    }

    @Override
    public void update(Observable o, Object o1) {
        updateCamps();
        updateProductes();
        updateProductors();
        updateAbonos();
        updateFitos();
    }
}
